package admin.statisticsToExcel;

import java.io.File;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.struts2.ServletActionContext;

import admin.service.member.LeaderServiceAdmin;
import teacher.bean.Teacher;

public class MemberToExcel {

	
	public static void memberExcel()
	{
        try {
            WritableWorkbook wwb = null; 
            String uploadPath = ServletActionContext.getServletContext()
					.getRealPath("/upload");
            
            File dir=new File(uploadPath);  
	       //如果这个目录不存在,则创建它  
	        if (!dir.exists()){  
	            dir.mkdir();  
	        } 
               // 创建可写入的Excel工作簿
            String fileName = uploadPath+"/"+"memberCount.xls";
               File file=new File(fileName);
               if (!file.exists()){
                   file.createNewFile();
               }
               //以fileName为文件名来创建一个Workbook
               wwb = Workbook.createWorkbook(file);
               // 创建工作表
               WritableSheet ws = wwb.createSheet("Test Shee 1", 0);                
             
               //要插入到的Excel表格的行号，默认从0开始
               Label aid= new Label(0, 0, "专家类别");//表示第
               Label aname= new Label(1, 0, "控制理论与控制工程");//表示第
               Label aprojectName= new Label(2, 0, "机器人系统与智能装备");
               Label alevel= new Label(3, 0, "模式识别与智能系统");   
               Label apeople= new Label(4, 0, "综合自动化与智能交通");
         
               ws.addCell(aid);
               ws.addCell(aname);
               ws.addCell(aprojectName);
               ws.addCell(alevel);
               ws.addCell(apeople);
              
               
               LeaderServiceAdmin ls=new LeaderServiceAdmin();
 
               for (int i = 0; i < 4; i++) 
               {  
            	  Teacher tea =new Teacher();
            	  tea.setDirection(i);
            	  for(int j=1;j<20;j++)
            	 
            	  {  Label aaid= new Label(i+1, j, ls.getCountOfExpertClass(j, tea)+"");
                  ws.addCell(aaid);
                  
            	  } 
              
                 
               }  
               Label id1= new Label(0, 1, "中国科学院工程院院士"+"");
               Label id2= new Label(0, 2,"国家千人计划入选者 "+"");
               Label id3= new Label(0, 3, "军队科技领军人才培养对象  "+"");
               Label id4= new Label(0, 4, "长江学者特聘讲座教授 "+"");
               Label id5= new Label(0, 5, "国家杰青基金获得者"+"");
               Label id6= new Label(0, 6, "973首席科学家  "+"");
               Label id7= new Label(0, 7, "国家级教学名师 "+"");
               Label id8= new Label(0, 8, "教育部高校青年教师奖获得者 "+"");
               Label id9= new Label(0, 9, "教育部跨世纪人才 "+"");
               Label id10= new Label(0, 10, "省特级专家 "+"");
               Label id11= new Label(0, 11, "省千人计划入选者"+"");
               Label id12= new Label(0, 12, "钱江特聘教授 "+"");
               Label id13= new Label(0, 13, "省“151人才工程”重点资助对象"+"");
               Label id14= new Label(0, 14, "省“151人才工程”一层次 "+"");
               Label id15= new Label(0, 15, "省“151人才工程”二层次 "+"");
               Label id16= new Label(0, 16, "省“151人才工程”三层次 "+"");
               Label id17= new Label(0, 17, "省高校中青年学科带头人"+"");
               Label id18= new Label(0, 18, "省级教学名师 "+"");
               Label id19= new Label(0, 19, "国家青年千人计划 "+"");
          
               ws.addCell(id1);
               ws.addCell(id2);
               ws.addCell(id3);
               ws.addCell(id4);
               ws.addCell(id5);
               ws.addCell(id6);
               ws.addCell(id7);
               ws.addCell(id8);
               ws.addCell(id9);
               ws.addCell(id10);
               ws.addCell(id11);
               ws.addCell(id12);
               ws.addCell(id13);
               ws.addCell(id14);
               ws.addCell(id15);
               ws.addCell(id16);
               ws.addCell(id17);
               ws.addCell(id18);
               ws.addCell(id19);
               
              //写进文档
               wwb.write();
              // 关闭Excel工作簿对象
               wwb.close();     
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }
}
